<?php
/*********************************************
 *  CPG Dragonfly™ CMS
 *********************************************
	Copyright © since 2010 by CPG-Nuke Dev Team
	http://dragonflycms.org

	Dragonfly is released under the terms and conditions
	of the GNU GPL version 2 or any later version
*/

namespace Poodle\Crypt;

class Fallback extends \Poodle\Crypt_Base
{

	public static function listCiphers() { return array('twofish'); }
	public static function listModes()   { return array(); }

	public function Encrypt(&$Data, $WeakKey)
	{
		# Convert data into a serialized string for single packing
		$SecretData = serialize($Data);
		# handle potential compression
		$this->compressor($SecretData);
		# Regenerate hardened key from weak key
		$key  = sha1($this->options['salt'] . $WeakKey);
		# Return the scrambled data stream
		return $this->Scramble($SecretData, $key);
	}

	public function Decrypt(&$SecretData, $WeakKey)
	{
		# Regenerate hardened key from weak key
		$key  = sha1($this->options['salt'] . $WeakKey);
		# Descramble data
		$data = $this->Descramble($SecretData, $key);
		# handle potential decompression
		$this->compressor($data, true);
		# Convert data from a serialized string and return
		return unserialize($data);
	}

}
